package aria.my12306.aria.my12306.myFragment;


import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;

import aria.my12306.LoginActivity;
import aria.my12306.R;
import aria.my12306.aria.my12306.my.MyAccountActivity;
import aria.my12306.aria.my12306.my.MyContactActivity;
import aria.my12306.aria.my12306.my.MyPasswordActivity;

/**
 * Created by wang5 on 2016/8/23.
 */
public class MyFragment extends android.support.v4.app.Fragment{
    private Button btnLoginOut;/*btnAccount,btnContact,btnPassword;*/
    private ListView lv;
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment1,container,false);
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        btnLoginOut=(Button)getActivity().findViewById(R.id.loginOut);
        lv=(ListView)getActivity().findViewById(R.id.myList);

        String[] data = getResources().getStringArray(R.array.my_ist_data);
        ArrayAdapter<String> adapter=new ArrayAdapter<String>(getActivity(),android.R
                .layout.simple_list_item_1,data);
        lv.setAdapter(adapter);
        lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Intent i=new Intent();
                switch (position) {
                    case 0:
                        i.setClass(getActivity(),MyContactActivity.class);
                        break;
                    case 1:
                        i.setClass(getActivity(),MyAccountActivity.class);
                        break;
                    case 2:
                        i.setClass(getActivity(),MyPasswordActivity.class);
                        break;
                }
                startActivity(i);
            }
        });
        MyButtonListenr listenr=new MyButtonListenr();

        btnLoginOut.setOnClickListener(listenr);

    }
    class  MyButtonListenr implements View.OnClickListener{
        @Override
        public void onClick(View v) {
            Intent i=new Intent();
            i.setClass(getActivity(),LoginActivity.class);
            startActivity(i);
            /*switch (v.getId()){
                case R.id.myAccount:
                    i.setClass(MainActivity.this, MyAccountActivity.class);
                    startActivity(i);
                    break;
                case R.id.myContact:
                    i.setClass(MainActivity.this, MyContactActivity.class);
                    startActivity(i);
                    break;
                case R.id.myPassword:
                    i.setClass(MainActivity.this, MyPasswordActivity.class);
                    startActivity(i);
                    break;
                case R.id.loginOut:
                    i.setClass(MainActivity.this, LoginActivity.class);
                    startActivity(i);
                    break;*/
        }
    }
}

